package com.itheima.service.Impl;

import com.itheima.domain.Admin;
import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import com.itheima.utils.MapperUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImpl implements UserService {


    @Override
    //通过email和pwd获取管理员对象
    public Admin findByEmailAndPwd(String email, String pwd) {
        Admin admin =null;
        //通过工具类获取sqlSession
        SqlSession sqlSession = MapperUtils.getSqlSession();
        //获取映射对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //调用方法
        admin = mapper.findByEmailAndPwd(email,pwd);
        //提交事务
        //sqlSession.commit();
        //释放资源
        sqlSession.close();

        return admin;
    }

    @Override
    //获取用户集合
    public List<User> findAll() {
        List<User> list =null;
        //通过工具类获取sqlSession
        SqlSession sqlSession = MapperUtils.getSqlSession();
        //获取映射对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //调用方法
        list = mapper.findAll();
        //提交事务
        //sqlSession.commit();
        //释放资源
        sqlSession.close();
        return list;
    }


}
